Skip to content

fix the stack_chk_guard issue for bk7239n#7188

Open
ziliguo wants to merge 1 commit intoSamsung:masterfrom
bekencorp:BK7239N_dev
Open

fix the stack_chk_guard issue for bk7239n#7188
ziliguo wants to merge 1 commit intoSamsung:masterfrom
bekencorp:BK7239N_dev

Conversation

@ziliguo
Copy link
Contributor

@ziliguo ziliguo commented Mar 12, 2026

  • move the bk_stack_guard_setup function earlier
  • there is indeed an override: in board/bk7239n/src/components/bk_cli/Make.defs, it includes “-include $(TOPDIR)/Make.defs“ again, which causes CFLAGS to be reassigned and overwritten.

- move the bk_stack_guard_setup function earlier
- there is indeed an override: in board/bk7239n/src/components/bk_cli/Make.defs, it includes “-include $(TOPDIR)/Make.defs“ again, which causes CFLAGS to be reassigned and overwritten.
@sunghan-chang
Copy link
Contributor

@ziliguo Could you leave how you verified?

@Poly-J
Copy link
Contributor

Poly-J commented Mar 13, 2026

@ziliguo Could you leave how you verified?

Hello @sunghan-chang

Our verification is divided into two steps:

1.Only removed the duplicate references to Make.defs under bk_cli, which solved the issue of CFLAGS being overwritten. This way, the stack overflow problem can also be reproduced with the code from GitHub.

  1. Based on the above scenario where the issue can be reproduced, we moved the configuration of stack_chk_guard out of the board_init function and relocated it before os_start, and then re-verified that the above issue could not be reproduced.

This change not only ensures that the function of the stack guard is retained, but also resolves the issue of false stack overflow reports.

@sunghan-chang
Copy link
Contributor

@ziliguo Could you leave how you verified?

Hello @sunghan-chang

Our verification is divided into two steps:

1.Only removed the duplicate references to Make.defs under bk_cli, which solved the issue of CFLAGS being overwritten. This way, the stack overflow problem can also be reproduced with the code from GitHub.

  1. Based on the above scenario where the issue can be reproduced, we moved the configuration of stack_chk_guard out of the board_init function and relocated it before os_start, and then re-verified that the above issue could not be reproduced.

This change not only ensures that the function of the stack guard is retained, but also resolves the issue of false stack overflow reports.

@Poly-J Do you verify the stack guard functionality itself after enabling?

@Poly-J
Copy link
Contributor

Poly-J commented Mar 13, 2026

@ziliguo Could you leave how you verified?

Hello @sunghan-chang
Our verification is divided into two steps:
1.Only removed the duplicate references to Make.defs under bk_cli, which solved the issue of CFLAGS being overwritten. This way, the stack overflow problem can also be reproduced with the code from GitHub.

  1. Based on the above scenario where the issue can be reproduced, we moved the configuration of stack_chk_guard out of the board_init function and relocated it before os_start, and then re-verified that the above issue could not be reproduced.

This change not only ensures that the function of the stack guard is retained, but also resolves the issue of false stack overflow reports.

@Poly-J Do you verify the stack guard functionality itself after enabling?

Hello @sunghan-chang

Yes, I have also verified this with standalone functional testing. The test scenario I used was as follows: I constructed a function with a local-variable overflow and called it during system initialization。

the code is as follows:
`attribute((noinline))

static void test_stack_guard_overflow(void)

{

char buf[16];  

lldbg("test_stack_guard_overflow\r\n");

/* Intentional overflow - will trigger __stack_chk_fail if stack guard works */

memset(buf, 0x41, 32);  /* overflow 16 bytes */

}`

The test log is shown below:

_[i2c]I2C(0) init ok, baud_rate:0

i2c_uioregister: Registering /dev/i2c-0

[hal]spi select src_clk xtal

[cal]calibration_main(unknown-48Pin) over

[cal]rf cali flag in flash: valid

[cal]tx_i_dc_2G: 0x7e9,tx_q_dc_2G: 0x80f

[cal]tx_q_dc_5G: 0x819,tx_q_dc_5G: 0x812

[cal]invalid 2test_stack_guard_overflow: test_stack_guard_overflow

Stack guard warning, local buffer overflow!!!

===========================================================

Assertion details

===========================================================

print_assert_detail: Assertion failed at file:components/bk_init/components_init.c line: 320 task: AppBringUp_

At the same time, for the modified firmware, in addition to testing the stack guard functionality itself, we also tested other features such as Bluetooth and Wi‑Fi, and did not find any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants